package com.wgl.yygh.serivice.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wgl.cmnclient.inteface.DictFeignClient;
import com.wgl.model.enums.DictEnum;
import com.wgl.model.user.Patient;
import com.wgl.yygh.dao.PatientMapper;
import com.wgl.yygh.serivice.PatientService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wgl
 * @version 1.0.0
 * @ClassName PatientServiceImpl.java
 * @Description TODO
 * @createTime 2022年02月12日 10:30:00
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Resource
    private DictFeignClient dictFeignClient;

    @Override
    public List<Patient> fandAllUserId(Long userId) {
        QueryWrapper<Patient> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        List<Patient> list = baseMapper.selectList(queryWrapper);
        //远程调用得到 就诊人信息的身份证、地区等信息  调用数据字典模块
        list.stream().forEach(item ->{
            packPatient(item);
        });
        return list;
    }

    @Override
    public Patient getPatientId(Long id) {
        Patient patient = packPatient(baseMapper.selectById(id));

        return patient;
    }

    /**
    * @Author: Wgl
    * @Description: 其他参数的封装
    * @Date: 2022/2/12 10:50;
    * @param patient: ;
    * @return: void;
    */
    private Patient packPatient(Patient patient) {
//根据证件类型编码，获取证件类型具体指
        String certificatesTypeString =
                (String) dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType()).getData();//联系人证件
        //联系人证件类型
        String contactsCertificatesTypeString =
                (String) dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),patient.getContactsCertificatesType()).getData();
        //省
        String provinceString = (String) dictFeignClient.getName(patient.getProvinceCode()).getData();
        //市
        String cityString = (String) dictFeignClient.getName(patient.getCityCode()).getData();
        //区
        String districtString = (String) dictFeignClient.getName(patient.getDistrictCode()).getData();

        patient.getParam().put("certificatesTypeString", certificatesTypeString);
        patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        patient.getParam().put("provinceString", provinceString);
        patient.getParam().put("cityString", cityString);
        patient.getParam().put("districtString", districtString);
        patient.getParam().put("fullAddress", provinceString + cityString + districtString + patient.getAddress());
        return patient;
    }
}
